/**
 * Created by aresn on 16/7/5.
 */

var path = require("path")
var webpack = require("webpack")
var ExtractTextPlugin = require("extract-text-webpack-plugin")
function resolve(dir) {
  return path.join(__dirname, "..", dir)
}

module.exports = {
  // 入口
  entry: {
    main: "./src/main",
    vendors: [
      "vue",
      "vue-router",
      "iview",
      "highlightjs/highlight.pack.js",
      "clipboard"
    ]
  },
  // 输出
  output: {
    path: path.join(__dirname, "./docs/dist")
  },
  // 加载器
  module: {
    rules: [
      {
        test: /\.vue$/,
        use: [
          {
            loader: "vue-loader",
            options: {
              loaders: {
                less: ExtractTextPlugin.extract({
                  use: [
                    "css-loader?minimize",
                    "autoprefixer-loader",
                    "less-loader"
                  ],
                  fallback: "vue-style-loader"
                }),
                css: ExtractTextPlugin.extract({
                  use: [
                    "css-loader?minimize",
                    "autoprefixer-loader",
                    "less-loader"
                  ],
                  fallback: "vue-style-loader"
                })
              },
              postLoaders: {
                html: "babel-loader"
              }
            }
          },
          {
            loader: "iview-loader",
            options: {
              prefix: false
            }
          }
        ]
      },
      {
        test: /iview\/.*?js$/,
        loader: "babel-loader"
      },
      {
        test: /\.js$/,
        loader: "babel-loader",
        exclude: /node_modules/
      },
      {
        test: /\.css$/,
        use: ExtractTextPlugin.extract({
          use: "css-loader?minimize",
          fallback: "style-loader"
        })
      },
      {
        test: /\.less/,
        use: ExtractTextPlugin.extract({
          use: ["css-loader?minimize", "autoprefixer-loader", "less-loader"],
          fallback: "style-loader"
        })
      },
      {
        test: /\.scss$/,
        use: ["style-loader", "css-loader", "sass-loader?sourceMap"]
      },
      {
        test: /\.(gif|jpg|png|woff|svg|eot|ttf)\??.*$/,
        loader: "url-loader?limit=1024"
      },
      {
        test: /\.(html|tpl)$/,
        loader: "html-loader"
      }
    ]
  },
  resolve: {
    extensions: [".js", ".vue"],
    alias: {
      hljs: "highlightjs/highlight.pack.js",
      iCode: "../../components/code.vue",
      // 'vue': 'vue/dist/vue.esm.js',
      vue: "vue/dist/vue.runtime.js"
      // '@': resolve('src')
    }
  }
}
